﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Security.Principal;
using System.Web.Routing;

public class HandleLoggingAttribute : Controller
{

    protected override void OnActionExecuting(ActionExecutingContext filtercontext)
    {
        base.OnActionExecuting(filtercontext);

        if ((filtercontext
            .HttpContext
            .Session["id"] == null) && 
           ((filtercontext
               .Controller
               .ValueProvider
               .GetValue("controller")
               .RawValue
               .ToString() == "Solicitudes")))
        {
            return;
        }
        else
        {
            if ((filtercontext
                    .HttpContext
                    .Session["id"] == null) && 
               ((filtercontext
                    .Controller
                    .ValueProvider
                    .GetValue("controller")
                    .RawValue
                    .ToString() != "Inicio")))
            {
                if ((filtercontext
                        .HttpContext
                        .Session["id"] == null) && 
                   ((filtercontext
                        .Controller
                        .ValueProvider
                        .GetValue("controller")
                        .RawValue
                        .ToString() != "Solicitudes")))
                {
                    filtercontext.Result = new RedirectToRouteResult(
                    new RouteValueDictionary { { "controller", "Inicio" }, { "action", "AccesoSinCredencial" } });
                }
            }
        }


        //if ((filtercontext.Controller.ValueProvider.GetValue("controller").RawValue.ToString() != "Mantencion") )
        //{
        //filtercontext.Result = new RedirectToRouteResult(
        //new RouteValueDictionary { { "controller", "Mantencion" }, { "action", "Error" } });
        //}
    }
}
